﻿namespace Ngs.Boost.Test
{
    #region Using Directives
    using System;
    using System.Text;
    using System.Collections.Generic;
    using System.Linq;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using Moq;
    using Ngs.Data;
    #endregion

    /// <summary>
    /// Summary description for DataQuery
    /// </summary>
    [TestClass]
    public class DataQueryTest : UnitTest
    {
        public DataQueryTest()
        {
        }

        private DomainObject1 Convert(DomainEntity1 entity)
        {
            var obj = new DomainObject1();

            obj.Field1 = entity.Field1;
            obj.Field2 = entity.Field2;
            obj.Field3 = entity.Field3;

            return obj;
        }

        private Converter<DomainEntity1, DomainObject1> GetConverter()
        {
            return new Converter<DomainEntity1, DomainObject1>(Convert);
        }

        private IQueryable<DomainEntity1> CreateIQueryable()
        {
            return new List<DomainEntity1>
            {
                new DomainEntity1{ Field1 = "Jane", Field2=40, Field3= 2.4d},
                new DomainEntity1{ Field1 = "Dick", Field2=67, Field3= 963.27d},
                new DomainEntity1{ Field1 = "Tom", Field2=34, Field3= 325.05d},
                new DomainEntity1{ Field1 = "Sam", Field2=52, Field3= 533.98d}
            }.AsQueryable();
        }

        private IDataQuery<DomainObject1> CreateQuery()
        {
            return new DataQueryProxy<DomainObject1, DomainEntity1>(CreateIQueryable(), GetConverter());
        }

        [TestMethod]
        public void TestWhere1()
        {
            string field1 = "Tom";

            IDataQuery<DomainObject1> query = CreateQuery();
            List<DomainObject1> list = query.Where(o => o.Field1 == field1).ToList();

            Assert.AreEqual(1, list.Count);
            Assert.AreEqual(field1, list[0].Field1);
        }
    }
}
